<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.soa.workflow.request.*" %>
<%@ page import="java.util.HashMap" %>
<%--
  Created by IntelliJ IDEA.
  User: MECHREVO
  Date: 2021/9/24
  Time: 11:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%

    String creatorId = "1708";
    String workflowId = "54024";
    String requestName = "这条是测试明细表的流程";
    String isNextFlow = "0";
    Map<String, String> requestMainMap = new HashMap<>();

    requestMainMap.put("zbbmfzr", creatorId);
    String creatorDepartId = "4027";
    requestMainMap.put("zbbm", creatorDepartId);
    String dateCreated = "2022-02-25";
    requestMainMap.put("fkrq", dateCreated);

    out.println(workflowCreateByRequestMap(creatorId, workflowId, requestName, isNextFlow, requestMainMap));

%>
<%!

    public String workflowCreateByRequestMap(String creatorId, String workflowId, String requestName,
                                             String isNextFlow, Map<String, String> requestMainMap) {

        String requestid = "";
        RequestInfo requestInfo = new RequestInfo();
        //创建人Id
        requestInfo.setCreatorid(creatorId);
        //工作流Id
        requestInfo.setWorkflowid(workflowId);
        //请求标题
        requestInfo.setDescription(requestName);
        if (!"".equals(isNextFlow)) {
            requestInfo.setIsNextFlow(isNextFlow);
        }

        //主表字段
        MainTableInfo mainTableInfo = new MainTableInfo();
        Property[] propertyArray = new Property[requestMainMap.size()];
        int p = 0;
        for (Map.Entry<String, String> entry : requestMainMap.entrySet()) {
            propertyArray[p] = new Property();
            propertyArray[p].setName(Util.null2String(entry.getKey()));
            propertyArray[p].setValue(Util.null2String(entry.getValue()));

            p++;
        }
        mainTableInfo.setProperty(propertyArray);

        //明细表字段
                /*
        明细表
         */
        DetailTable[] detailTable = new DetailTable[1];
        /*
        明细表行
         */
        Row[] rows = new Row[1];
        /*
          明细表列
        */
        Cell[] cells = new Cell[1];
        cells[0] = new Cell();
        cells[0].setValue("2");
        cells[0].setName("CYCD");
        rows[0] = new Row();
        rows[0].setCell(cells);

        detailTable[0] = new DetailTable();
        detailTable[0].setRow(rows);
        detailTable[0].setTableDBName("FORMTABLE_MAIN_445_dt1");
        DetailTableInfo detailTableInfo = new DetailTableInfo();

        detailTableInfo.setDetailTable(detailTable);

        requestInfo.setMainTableInfo(mainTableInfo);
        requestInfo.setDetailTableInfo(detailTableInfo);

        RequestService service = new RequestService();
        //创建请求id
        try {
            requestid = service.createRequest(requestInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }


        return requestid;
    }
%>